package org.example;

public class main {
    public static void main(String[] args) {
        NewsDao dao =SimpleDaoFactory.getInstance();
        NewsServiceImpl service=new NewsServiceImpl();
        service.setDao(dao);

    }
    public static NewsDao getInstance(String key){
        switch (key){
            case "mysql":
                return new NewsDaoMysqlImpl();
            case "oracle":
                return new NewsDaoOracleImpl();
            case "redis":
                return new NewsDaoRedisImpl();
            default:
                throw new RuntimeException("无效的数据库类型"+key+",Dao获取失败");
        }
    }
    AbstractFactory factory=new MySqlDaoFactory();
    NewsDao dao=factory.getInstance();
    NewsServiceImpl service=new NewsServiceImpl();
    service.setDao(dao);


    Buyer  buyer=new IntermediaryImpl(new RealBuyer());
    String result=buyer.havealook();
     logger.debug(result);


     RealBuyer buyer=new IntermediarySubclass();
     String result=buyer.havealook();
     logger.debug(result);


     Buyer buyer=IntermediaryJdkProxyFactory.create(new RealBuyer());
     String result=buyer.havealook();
      logger.debug(result);

      RealBuyer buyer=IntermediaryJdkProxyFactory.create(RealBuyer.class);
      String result=buyer.havealook();
      logger.debug(result);
}
